//
//  CaseCell.m
//  Full_House
//
//  Created by 张忱 on 15-6-3.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "CaseCell.h"
#import "Case.h"
@implementation CaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel release];
        
        self.caseImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.caseImageView];
        [self.caseImageView release];
        
        self.userImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.userImageView];
        [self.userImageView release];
        
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.dateLabel];
        [self.dateLabel release];
        
        self.commentNumLabel = [[UILabel alloc] init];
        self.commentNumLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.commentNumLabel];
        [self.commentNumLabel release];
        
        self.likeNumLabel = [[UILabel alloc] init];
        self.likeNumLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.likeNumLabel];
        [self.likeNumLabel release];
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.caseImageView.frame = CGRectMake(10, 10, kWidth - 20, kHeight * 3 / 4 );
    
    self.userImageView.frame = CGRectMake(20, kHeight / 4 * 3 - 20, 80, kHeight / 4 + 10);
    
    self.titleLabel.frame = CGRectMake(120, kHeight / 4 * 3 + 15, kWidth - 120, 20);
    
    self.dateLabel.frame = CGRectMake(120, kHeight / 4 * 3 + 30, 100, 20);
    
    self.commentNumLabel.frame = CGRectMake(250, kHeight / 4 * 3 + 30, 50, 20);
    
    self.likeNumLabel.frame = CGRectMake(300, kHeight / 4 * 3 + 30, 50, 20);
}


- (void)setCase1:(Case *)case1
{
    if (_case1 != case1) {
        [_case1 release];
        _case1 = [case1 retain];
    }
    
    NSString *caseStr = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w213_h213_m0.jpg", case1.coverPhoto];
    
    NSURL *caseImageUrl = [NSURL URLWithString:caseStr];
    
    NSString *userImage = [[case1.user objectForKey:@"userImage"] objectForKey:@"medium"];
    
    NSURL *userImageUrl = [NSURL URLWithString:userImage];
    
    [self.caseImageView setImageWithURL:caseImageUrl];
    
    [self.userImageView setImageWithURL:userImageUrl];
    
    self.titleLabel.text = case1.title;
    
    self.dateLabel.text = case1.date;
    
    self.commentNumLabel.text = case1.commentNum;
    
    self.likeNumLabel.text = case1.likeNum;
    
}

- (void)dealloc
{
    [_caseImageView release];
    [_userImageView release];
    [_titleLabel release];
    [_dateLabel release];
    [_commentNumLabel release];
    [_likeNumLabel release];
    [_case1 release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
